home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Development / 3DMF parser / 0.9 version / MFRSLNTN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-24  |  4.4 KB  |  169 lines  |  [TEXT/MPS ]

  1. /*==============================================================================
  2.  *
  3.  *    File:        MFRSLNTN.C
  4.  *
  5.  *    Function:    Routines for saving information around reference resolution.
  6.  *
  7.  *    Author(s):    Rick Wong (RWW), Duet Development Corp.
  8.  *
  9.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  10.  *
  11.  *    Change History (most recent first):
  12.  *        Fabio    Changed file name to 8 characters
  13.  *        F3H_RWW    Make the resolution stuff work with external files.
  14.  *        F2N_RWW    File created.
  15.  *==============================================================================
  16.  */
  17.  
  18. #include "MFRSLNTN.H"
  19.  
  20. #include <string.h>
  21.  
  22. #include "MF3D.H"
  23. #include "MFERRORS.H"
  24. #include "MFINT64.H"
  25. #include "MFTYPES.H"
  26. #include "MFASSERT.H"
  27. #include "MFINTOBJ.H"
  28. #include "MFMACROS.H"
  29. #include "MFMEMORY.H"
  30.  
  31. /*==============================================================================
  32.  *    MF3D_PushResolution
  33.  *
  34.  *    Resolve a reference
  35.  *==============================================================================
  36.  */
  37. MF3DErr
  38. MF3D_PushResolution(
  39.     MF3D_FilePtr        ioMF3DFilePtr,         /* In:  MF3D file structure        */
  40.     MF3DReferenceObjPtr    inMF3DRefObjPtr,     /* In:  reference object        */
  41.     MF3DStorageObjPtr    inExternalFilePtr)    /* In:    external storage object    */
  42. {
  43.     MF3D_FilePtr            newFilePtr;
  44.     MF3DUns32                resState;
  45.     MF3DBinaryFilePosition    returnLoc;
  46.     MF3DErr                    result;
  47.  
  48.     result = kMF3DNoErr;
  49.  
  50.     MFASSERT(ioMF3DFilePtr->resStuff.reference == NULL);
  51.  
  52.     if (inMF3DRefObjPtr->refID == 0)
  53.     {    if (inExternalFilePtr == NULL)
  54.             result = kMF3DErrIllegalRefID;
  55.         else
  56.             resState = MF3D_ResolvingFile;
  57.     }
  58.     else
  59.     {    resState = MF3D_ResolvingReference;
  60.     }
  61.  
  62.     if (result == kMF3DNoErr)
  63.     {    SetInt64ToZero(returnLoc);
  64.         if (inExternalFilePtr != NULL)
  65.         {    /* Got outside object */
  66.             result = MF3DOpenInputStdCFile(
  67.                     inExternalFilePtr->pathName, &newFilePtr);
  68.         }
  69.         else
  70.         {    /* Duplicate current file for reference */
  71.             MF3D_Allocate(newFilePtr);
  72.  
  73.             if (result == kMF3DNoErr)
  74.                 result = MF3DTellPosition(ioMF3DFilePtr, &returnLoc);
  75.  
  76.             if (result == kMF3DNoErr)
  77.                 memcpy(newFilePtr, ioMF3DFilePtr, sizeof(*newFilePtr));
  78.  
  79.             
  80.         }
  81.     }
  82.  
  83.     if (result == kMF3DNoErr && resState == MF3D_ResolvingReference)
  84.     {    MF3DUns32                    objIndex, numObjTableEntries;
  85.         MF3D_ObjectTableEntryPtr    objTableEntryPtr;
  86.  
  87.         numObjTableEntries = newFilePtr->objTable.numObjects;
  88.         objTableEntryPtr = newFilePtr->objTable.objects;
  89.         for (objIndex = 0;
  90.                 objTableEntryPtr->objRefID != inMF3DRefObjPtr->refID;
  91.                 ++objIndex, ++objTableEntryPtr)
  92.         {    if (objIndex >= numObjTableEntries)
  93.             {    result = kMF3DErrReferenceNotFound;
  94.                 break;
  95.             }
  96.         }
  97.  
  98.         if (result == kMF3DNoErr)
  99.         {    result = MF3DSeekPosition(newFilePtr,
  100.                     objTableEntryPtr->objLocation);
  101.         }
  102.  
  103.         if (result != kMF3DNoErr)
  104.         {    if (inExternalFilePtr != NULL)
  105.                 MF3DClose(newFilePtr);
  106.             else
  107.                 MF3D_Free(newFilePtr);
  108.         }
  109.     }
  110.  
  111.     if (result == kMF3DNoErr)
  112.     {    MFASSERT(ioMF3DFilePtr->resStuff.reference == NULL);
  113.  
  114.         newFilePtr->resStuff.parent = ioMF3DFilePtr;
  115.         newFilePtr->resStuff.resState = resState;
  116.         newFilePtr->resStuff.reference = MF3D_Malloc(0);
  117.         newFilePtr->readBuffer.buf = NULL;
  118.         newFilePtr->inContainer = 0;
  119.         newFilePtr->typeTable.nTypes = 0;
  120.         newFilePtr->typeTable.types = MF3D_Malloc(0);
  121.         /* NOTE: returnLoc is only valid for internal references */
  122.         AssignInt64(newFilePtr->resStuff.returnLoc, returnLoc);
  123.         ioMF3DFilePtr->resStuff.reference = newFilePtr;
  124.     }
  125.  
  126.     return result;
  127. }
  128.  
  129. /*==============================================================================
  130.  *    MF3D_PopResolution
  131.  *
  132.  *    Close inMF3DFilePtr.
  133.  *==============================================================================
  134.  */
  135. MF3DErr
  136. MF3D_PopResolution(
  137.     MF3D_FilePtr    inMF3DFilePtr)
  138. {
  139.     MF3D_FilePtr            parentFilePtr;
  140.     MF3DBinaryFilePosition    zero;
  141.     MF3DErr                    result;
  142.  
  143.     result = kMF3DNoErr;
  144.  
  145.     parentFilePtr = inMF3DFilePtr->resStuff.parent;
  146.     MFASSERT(parentFilePtr != NULL);
  147.  
  148.     if (inMF3DFilePtr->resStuff.reference != NULL)
  149.         result = MF3D_PopResolution(inMF3DFilePtr->resStuff.reference);
  150.  
  151.     parentFilePtr->resStuff.reference = NULL;
  152.  
  153.     /* Was it an external reference? */
  154.     SetInt64ToZero(zero);
  155.     if (CompareInt64(inMF3DFilePtr->resStuff.returnLoc, zero) == 0)
  156.     {    result = MF3DClose(inMF3DFilePtr);
  157.     }
  158.     else
  159.     {    /* NOTE: returnLoc is only valid for internal references */
  160.         result = MF3DSeekPosition(inMF3DFilePtr,
  161.                 inMF3DFilePtr->resStuff.returnLoc);
  162.     }
  163.  
  164.     if (inMF3DFilePtr->resStuff.resState > MF3D_ResolvingFile)
  165.         result = kMF3DErrNotEnoughEndGroups;
  166.  
  167.     return result;
  168. }
  169.